ComputeGhostProbabilities <- function(PartTree,PartProbs,BranchIdx) {
    
  # This function determines the "Ghost" probabilities for each component
  #   AKA the "Flattened Hierarchy" probabilities.
  # The purpose of this altered probability is to make all component 
  #   probabilities truly independent of each other.
  #
  # ISSUES:
  # Currently the largest issue is deciding what is the valid relationship
  #   between the parent probability and the combinatorics of the 
  #   childrens' probabilities.  
  # As of 11/29/12 the calculations below represent one combinatorial event
  #   and should really look to BranchedNcK.R for all possible events.
  #
  # Inputs
  #   PartTree - 1xB vector - gives the part's level in the hierarchy, 
  #              higher = down rabbit hole.  Since this is for a specific 
  #              rabbit hole, the highest level can have more than one entry.
  #
  #   PartProbs - Nx1 vector indicating each part's probability of failure.
  #
  #   BranchIdx - 1xN list for each part listing the sub-components 
  #               of its branch or children
  #
  # Outputs
  #   GhostProbs - 1xN vector giving the "Ghost Probability" of each components
  #                equal to the parent's first level down, aka first 
  #                children's level
  #
  # Written by: Sean Gonzalez, Willcor Inc., October 2012
  #________________________________________________________________________
  
  # Initialize 
  numTotalParts = length(PartTree)
  GhostProbs = numeric(numTotalParts)
  
  for (p in 1:numTotalParts) {
    compIdx <- BranchIdx[[p]]
    nextLevel = min(PartTree[compIdx])
    levelIdx = compIdx == nextLevel
    # I only need to flatten to the next level, then deal with 
    # the levels below as I loop through the other components
    CompProbs = PartProbs[compIdx]
    #reduce the PartProbs vector to contain only probabilities for
    #parts in the compIdx vector
    GhostProbs[p] = PartProbs[p] /prod(PartProbs[levelIdx])
  }
  return(GhostProbs)
}